package hw;

import java.util.ArrayList;
import java.util.List;

public class HwTest {
	 public static void main(String[] args) {
//defines cargo companies, and in which cities they are present			
			Map map = new Map();		
			List<CargoCompany> companies= new ArrayList<CargoCompany>();
			CargoCompany one = new CargoCompany("Red Cargo",map, 0.50, 1.00, 2.00);
			one.getCities().add("Ankara");
			one.getCities().add("Izmir");
			one.getCities().add("Istanbul");
			one.getCities().add("Bursa");
			one.getCities().add("Manisa");
			companies.add(one);
			
			CargoCompany two = new CargoCompany("Blue Cargo",map, 1.25, 0.75, 1.00);
			two.getCities().add("Izmir");
			two.getCities().add("Istanbul");
			two.getCities().add("Bursa");
			two.getCities().add("Manisa");
			companies.add(two);
			
	        CargoCompany three = new CargoCompany ("Yellow Cargo",map, 0.75, 1.25, 2.00);
	        three.getCities().add("Istanbul");
	        three.getCities().add("Izmir");
	        three.getCities().add("Ankara");
	        companies.add(three);
	        
	        Shipment shipment = new Shipment("Bursa","Izmir",-3,100); //example input
	        
        
	        CargoCompany cheaperCompany = null;
	        double cheaperPrice = 0;
	        for (CargoCompany company : companies){
	        	double price = company.calculateprice(shipment);
	        	 if (price > 0.0){
	        	System.out.println("Company Name :"+company.getName() + " price : "+price);
	        	 }
	        	if (price != 0.0) //ignores the case where the company is not available in the source city so the price is 0
	        	if (cheaperCompany == null ){
	        		cheaperCompany = company;
	        		cheaperPrice = price;
	        		
	        	} else {
	        		if (cheaperPrice > price){
	        			cheaperCompany = company;
	        			cheaperPrice = price;
	        		}
	        	}
	        	
	        }
	       
	       System.out.println("The cheapest Company Name: "+ cheaperCompany.getName() + " price: " + cheaperPrice);
	         
	}
}
